package com.iot08.api.service;

import com.iot08.common.entity.app.HeartRateSetting;
import com.iot08.common.service.base.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @version 1.0
 * @Description:
 * @author: Rock
 * @time: 2021/3/8 18:33
 */
@Slf4j
@Service
public class HeartRateSettingService extends BaseService<HeartRateSetting> {

    /**
     * 获取记录，没有记录则添加默认记录
     *
     * @param id
     * @param openid
     * @time: 2021/3/8 19:09
     * @author: Rock
     * @version 1.0
     */
    public HeartRateSetting getById(String id, String openid) {
        HeartRateSetting heartRateSetting = this.findById(id);
        if (heartRateSetting == null) {
            heartRateSetting = new HeartRateSetting();
            heartRateSetting.setId(id);
            heartRateSetting.setSetChangeTime(System.currentTimeMillis() / 1000);
            heartRateSetting.setOpenid(openid);
            heartRateSetting.setLastHeart("0");
            heartRateSetting.setLastDataTime(0l);
            heartRateSetting.setSwitchStatus(0);
            heartRateSetting.setUpper("100");
            heartRateSetting.setLower("60");
            heartRateSetting.setHeartFreq("120");
            this.save(heartRateSetting);
            log.info("创建心率配置记录 imei: {}" ,id);
        }
        return heartRateSetting;
    }


}
